package edu.stu.cs.software.family.favoriteshop.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers;
import org.springframework.data.domain.ExampleMatcher.StringMatcher;
import org.springframework.stereotype.Component;
import edu.stu.cs.software.family.base.service.impl.GenericManagerImpl;
import edu.stu.cs.software.family.favoriteshop.dao.FavoriteDao;
import edu.stu.cs.software.family.favoriteshop.domain.Favorite;
import edu.stu.cs.software.family.favoriteshop.service.FavoriteManager;
/**
 * 
 * @author Administrator
 *
 */
@Component
public class FavoriteManagerImpl extends GenericManagerImpl<Favorite, Long> implements FavoriteManager{

	FavoriteDao favoriteDao;
	@Override
	public List<Favorite> findByName(String favoriteName) {
		Favorite queryObject =new Favorite();
		queryObject.setFavoriteName(favoriteName);
		ExampleMatcher matcher =ExampleMatcher.matching()
				.withStringMatcher(StringMatcher.CONTAINING)
				.withIgnoreCase(true)
				.withMatcher("favoriteName", GenericPropertyMatchers.startsWith());
		Example<Favorite> ex = Example.of(queryObject, matcher);
		List<Favorite> result =this.favoriteDao.findAll(ex);
		return result;
	}
	
	@Override
	public List<Favorite> findByAddr(String addr) {		
		Favorite queryObject =new Favorite();
		queryObject.setAddr(addr);
		ExampleMatcher matcher =ExampleMatcher.matching()
				.withStringMatcher(StringMatcher.CONTAINING)
				.withIgnoreCase(true)
				.withMatcher("addr", GenericPropertyMatchers.startsWith());
		Example<Favorite> ex = Example.of(queryObject, matcher);
		List<Favorite> result =this.favoriteDao.findAll(ex);
		return result;
	}
	@Autowired
	public void setFavoriteDao(FavoriteDao favoriteDao) {
		this.favoriteDao = favoriteDao;
		this.dao=favoriteDao;
	}

}